#include "myError.h"

MyError::MyError(int code, QString desc) : exception(desc.toStdString().c_str()), m_code(code), m_desc(desc) {
	
}

MyError::MyError(MyErrorType::ErrorType error) : m_code(error.code), m_desc(error.msg) { }

MyError::MyError(const MyError& other) {
	this->m_code = other.m_code;
	this->m_desc = other.m_desc;
}

MyError& MyError::operator=(const MyError& other) {
	this->m_code = other.m_code;
	this->m_desc = other.m_desc;
	return *this;
}

const QString& MyError::type() const {
	if (m_code == 0) {
		return "NONE_ERROR";
	} else if (m_code == -2) {
		return "RUNTIME_EXCEPTION";
	} else if (m_code == -1) {
		return "UNKNOW_ERROR";
	} else if (m_code >= 2000 && m_code < 3000) {
		return "CAMERA_ERROR";
	} else if (m_code >= 3000 && m_code < 4000) {
		return "IMAGE_PROCESS_ERROR";
	} else if (m_code >= 4000 && m_code < 5000) {
		return "SERIAL_ERROR";
	} else if (m_code >= 5000 && m_code < 6000) {
		return "DATABASE_ERROR";
	} else if (m_code >= 6000 && m_code < 7000) {
		return "FILE_ERROR";
	}
	return "UNKNOW_ERROR";
}

const int& MyError::code() const {
	return m_code;
}

const QString& MyError::desc() const {
	return m_desc;
}

const QString MyError::detail() const {
	return QString("%1[code:%2, 错误信息:%23").arg(type()).arg(m_code).arg(m_desc);
}
